home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGASIC / BASFILES.LZH / NFRMAT.BAS < prev    next >
BASIC Source File  |  1988-09-10  |  5KB  |  198 lines

  1. '$INCLUDE:'QBTOOLS.INC'
  2. '----------------------------------
  3. '| NFRMAT - Formats numeric entry
  4. '| SYNTAX:
  5. '| CALL nfrmat(strng$,mode%,p%)
  6. '|                |      |   +- Position of "-" for mode 6
  7. '|                |      +----- Mode or formatting level
  8. '|                +------------ String or variable to format.
  9. '|                              If formatting is requested, the formatted
  10. '|                              string is returned in this variable.
  11. '|
  12. '| mode 0 = Disallow "-" as an element (numbers ONLY)
  13. '|      1 = Allow "-" as an element
  14. '|      2 = Formatting to phone type (7 digit: xxx-xxxx)
  15. '|      3 = Formatting to phone type (10 digit: xxx-xxx-xxxx)
  16. '|      4 = Formatting to social security style (xxx-xx-xxxx)
  17. '|      5 = Extract numbers from string sent, no exclusions
  18. '|      6 = Extract numbers, place "-" in position p
  19. '+-----------------------------------
  20. '|  Possible Returns:
  21. '|
  22. '| M=99;STRNG$="Numeric Entry Only!" -Input had non numeric characters
  23. '| M=98;STRNG$="Too long-Looking for xx Digit [Phone/Social Security] Number!"
  24. '| M=97;STRNG$="Too short-Looking for xx Digit [Phone/Social Security] Number!"
  25. '| M=50;STRNG$="Programmer Error - Invalid mode specified." (you screwed up)
  26. '| M=unchanged;STRNG$=numeric string formatted to specifications
  27. '+----------------------------------
  28. '| Copr. InfoSoft 1986, 1987, 1988
  29. '| ALL RIGHTS RESERVED
  30. '-----------------------------------
  31. SUB numberformat(nst$, m%, p%) STATIC
  32.    DEFINT A-Z
  33.    STATIC c$, l, z, l1, x                ' maybe narry$() and raw$() too
  34.  
  35.    st$="": mst$="": l=0 : z=1
  36.  
  37.    l1=LEN(nst$)
  38.    IF l1=0 AND m=6 THEN EXIT SUB          ' get LEN of strng passed
  39.    REDIM raw$(l1)
  40.  
  41.    FOR y=1 TO l1                    'count numeric elements in st$
  42.       c$=MID$(nst$,y,1)
  43.       raw$(y)=c$                    ' parse elements into array
  44.       IF ASC(c$) =>48 AND ASC(c$) <=57 THEN
  45.          l=l+1
  46.       END IF
  47.    NEXT y                           ' l is number of nums, raw$ is raw array
  48.  
  49.    REDIM narry$(l)                  'dim array to exact length
  50.  
  51.    FOR x=1 TO l1                    ' store just the nums in array
  52.        c$=raw$(x)
  53.        IF INSTR("0123456789",c$) THEN
  54.           narry$(z)=c$
  55.           z=z+1
  56.        END IF
  57.    NEXT x
  58.  
  59. '
  60.    SELECT CASE m
  61.      CASE 0 : GOTO num.only
  62.      CASE 1 : GOTO dash
  63.      CASE 2 : GOTO phone7
  64.      CASE 3 : GOTO phone10
  65.      CASE 4 : GOTO soc.sec
  66.      CASE 5 : GOTO extr.num
  67.      CASE 6 : GOTO acct.num
  68.      CASE ELSE
  69.        m=50
  70.        nst$="Invalid mode specified."
  71.        EXIT SUB
  72.   END SELECT
  73.  
  74.  
  75. num.only:
  76.    nst$=""
  77.    FOR x=1 TO l1
  78.        c$=raw$(x)
  79.        IF ASC(c$) < 47 OR ASC(c$) >58 THEN   ' check for num between 0-9
  80.           nst$="Numeric Entry Only"
  81.           m=99
  82.           EXIT SUB
  83.        ELSE
  84.           nst$=nst$+c$
  85.        END IF
  86.    NEXT x
  87.    EXIT SUB
  88.  
  89. dash:
  90.    nst$=""
  91.    FOR x=1 TO l1
  92.        c$=raw$(x)
  93.        IF INSTR("0123456789-",c$) THEN
  94.           nst$=nst$+c$
  95.        ELSE
  96.           nst$="Invalid Characters in Input"
  97.           m=99
  98.           EXIT SUB
  99.        END IF
  100.    NEXT X
  101.    EXIT SUB
  102.  
  103. phone7:
  104.   IF l>7 THEN
  105.       nst$="Too long - Looking for a 7 Digit Phone Number!"
  106.       m=98
  107.       EXIT SUB
  108.   ELSEIF l<7 THEN
  109.       nst$="Too short - Looking for a 7 Digit Phone Number!"
  110.       m=97
  111.       EXIT SUB
  112.   END IF
  113.   nst$=""
  114.  
  115.   FOR x=(l-6) TO (l-4)
  116.       nst$=nst$+narry$(x)
  117.   NEXT x
  118.   nst$=nst$+"-"
  119. '
  120.  
  121.   FOR x=(l-3) TO l
  122.       nst$=nst$+narry$(x)
  123.   NEXT x
  124.   EXIT SUB
  125.  
  126. phone10:
  127.   IF l>10 THEN
  128.      nst$="Too long - Looking for a 10 Digit Phone Number!"
  129.      m=98
  130.      EXIT SUB
  131.   ELSEIF l<10 AND m=3 THEN
  132.      nst$="Too short - Looking for a 10 Digit Phone Number!"
  133.      m=97
  134.      EXIT SUB
  135.   END IF
  136.  
  137.   nst$="("+narry$(1)+narry$(2)+narry$(3)+") "
  138.  
  139.   FOR x=4 TO 6
  140.       nst$=nst$+narry$(x)
  141.   NEXT x
  142.   nst$=nst$+"-"
  143.   FOR x=7 TO 10
  144.       nst$=nst$+narry$(x)
  145.   NEXT x
  146.   EXIT SUB
  147.  
  148. soc.sec:
  149.   nst$=""
  150.   IF l>9 THEN
  151.      nst$="Too long - Social Security Numbers are only 9 Digits !"
  152.      m=98
  153.      EXIT SUB
  154.   ELSEIF l<9 THEN
  155.      nst$="Too short - Social Security Numbers are 9 Digits !"
  156.      m=97
  157.      EXIT SUB
  158.   END IF
  159.  
  160.   FOR x=1 TO 3
  161.      nst$=nst$+narry$(x)
  162.   NEXT x
  163.  
  164.   nst$=nst$+"-"
  165.  
  166.   FOR x=4 TO 5
  167.      nst$=nst$+narry$(x)
  168.   NEXT x
  169.  
  170.   nst$=nst$+"-"
  171.  
  172.   FOR x=6 TO 9
  173.      nst$=nst$+narry$(x)
  174.   NEXT x
  175.   EXIT SUB
  176.  
  177. '
  178.  
  179. extr.num:
  180.   nst$=""
  181.    FOR x=1 TO l
  182.       nst$=nst$+narry$(x)
  183.    NEXT x
  184.    EXIT SUB
  185.  
  186. acct.num:
  187.    nst$=""
  188.    FOR x=1 TO (p-1)
  189.      nst$=nst$+narry$(x)
  190.    NEXT x
  191.    nst$=nst$+"-"
  192.  
  193.    FOR x=p TO l
  194.       nst$=nst$+narry$(x)
  195.    NEXT x
  196.  
  197. END SUB
  198.